-----------------------------------
--
-- Zone: The_Garden_of_RuHmet (35)
--
-----------------------------------
package.loaded["scripts/zones/The_Garden_of_RuHmet/TextIDs"] = nil;
-----------------------------------

require("scripts/globals/settings");
require("scripts/zones/The_Garden_of_RuHmet/TextIDs");
require("scripts/globals/missions");
require("scripts/globals/keyitems");

-----------------------------------
-- onInitialize
-----------------------------------

function onInitialize(zone)

	zone:registerRegion(1, -421, -2, 377, -417, 0, 381);    -- RDC
	zone:registerRegion(2, -422, -2, -422, -418, 0, -418);  -- +1
	zone:registerRegion(3, 418, -2, 378, 422, 0, 382);      -- +2

	zone:registerRegion(4, -506, -4, 697, -500, 4, 703);    -- Hume niv 0 150 vers niv 1
	zone:registerRegion(5, -507, -4, -103, -501, 4, -97);   -- Hume niv 1 158 vers niv 0
	zone:registerRegion(6, -339, -4, -103, -332, 4, -97);   -- Hume niv 1 159 vers niv 2
	zone:registerRegion(7, 501, -4, 697, 507, 4, 702);      -- Hume niv 2 169 vers niv 1
	zone:registerRegion(8, 332, -4, 696, 339, 4, 702);      -- Hume niv 2 168 vers niv 3
	zone:registerRegion(9, 332, -4, -102, 338, 4, -97);     -- Hume niv 3 178 vers niv 2

	zone:registerRegion(10, -102, -4, 541, -96, 4, 546);    -- Elvaan niv 0 151 vers niv 1
	zone:registerRegion(11, -103, -4, -259, -96, 4, -252);  -- Elvaan niv 1 160 vers niv 0
	zone:registerRegion(12, -103, -4, -427, -67, 4, -420);  -- Elvaan niv 1 161 vers niv 2
	zone:registerRegion(13, 736, -4, 372, 742, 4, 379);     -- Elvaan niv 2 171 vers niv 1
	zone:registerRegion(14, 736, -4, 540, 743, 4, 546);     -- Elvaan niv 2 170 vers niv 3
	zone:registerRegion(15, 737, -4, -259, 743, 4, -252);   -- Elvaan niv 3 179 vers niv 2

	zone:registerRegion(16, -178, -4, 97, -173, 4, 103);    -- Galka niv 0 152 vers niv 1
	zone:registerRegion(17, -178, -4, -703, -173, 4, -697); -- Galka niv 1 162 vers niv 0
	zone:registerRegion(18, -347, -4, -703, -340, 4, -696); -- Galka niv 1 163 vers niv 2
	zone:registerRegion(19, 492, -4, 96, 499, 4, 103);      -- Galka niv 2 173 vers niv 1
	zone:registerRegion(20, 660, -4, 96, 667, 4, 102);      -- Galka niv 2 172 vers niv 3
	zone:registerRegion(21, 660, -4, -702, 667, 4, -697);   -- Galka niv 3 180 vers niv 2

	zone:registerRegion(22, -498, -4, 97, -492, 4, 102);    -- Taru niv 0 153 vers niv 1
	zone:registerRegion(23, -499, -4, -703, -492, 4, -697); -- Taru niv 1 164 vers niv 0
	zone:registerRegion(24, -667, -4, -703, -661, 4, -696); -- Taru niv 1 165 vers niv 2
	zone:registerRegion(25, 172, -4, 96, 178, 4, 102);      -- Taru niv 2 175 vers niv 1
	zone:registerRegion(26, 340, -4, 97, 347, 4, 102);      -- Taru niv 2 174 vers niv 3
	zone:registerRegion(27, 340, -4, -703, 347, 4, -697);   -- Taru niv 3 181 vers niv 2

	zone:registerRegion(28, -742, -4, 373, -736, 4, 379);   -- Mithra niv 0 154 vers niv 1
	zone:registerRegion(29, -743, -4, -427, -736, 4, -421)  -- Mithra niv 1 166 vers niv 0
	zone:registerRegion(30, -742, -4, -259, -737, 4, -252); -- Mithra niv 1 167 vers niv 2
	zone:registerRegion(31, 97, -4, 541, 102, 4, 547);      -- Mithra niv 2 177 vers niv 1
	zone:registerRegion(32, 97, -4, 372, 102, 4, 379);      -- Mithra niv 2 176 vers niv 3
	zone:registerRegion(33, 97, -4, -427, 102, 4, -421);    -- Mithra niv 3 182 vers niv 2

end;

-----------------------------------
-- onConquestUpdate
-----------------------------------

function onConquestUpdate(zone, updatetype)
    local players = zone:getPlayers();

    for name, player in pairs(players) do
        conquestUpdate(zone, player, updatetype, CONQUEST_BASE);
    end
end;

-----------------------------------
-- onZoneIn
-----------------------------------

function onZoneIn(player,prevZone)
	local cs = -1;

	if ((player:getXPos() == 0) and (player:getYPos() == 0) and (player:getZPos() == 0)) then
		player:setPos(-351.136,-2.25,-380,253);
	end

	if (player:getCurrentMission(COP) == WHEN_ANGELS_FALL and player:getVar("PromathiaStatus")==0) then
		cs = 0x00C9 ;
	end

	player:setVar("Ru-Hmet-TP",0);

	return cs;
end;

-----------------------------------
-- onRegionEnter
-----------------------------------

function onRegionEnter(player,region)
	if (player:getVar("Ru-Hmet-TP")==0 and player:getAnimation()==0) then
	switch (region:GetRegionID()): caseof
	{
		[1] = function (x)
			if (player:getCurrentMission(COP)==DAWN or player:hasCompletedMission(COP,DAWN) or player:hasCompletedMission(COP,THE_LAST_VERSE)) then
				player:startEvent(0x0065);
			else
				player:startEvent(0x009B);
			end
		end, -- 101

		[2] = function (x)
			if (player:hasKeyItem(BRAND_OF_DAWN) and player:hasKeyItem(BRAND_OF_TWILIGHT)) then
				player:startEvent(0x009C);
			else
				player:startEvent(0x00B7);
			end
		end, -- 102

		[3] = function (x)
			player:startEvent(0x0067);
		end, -- 103

		[4] = function (x) player:startEvent(0x0096); end, -- Hume niv 0 150 vers niv 1
		[5] = function (x) player:startEvent(0x009E); end, -- Hume niv 1 158 vers niv 0
		[6] = function (x) player:startEvent(0x009F); end, -- Hume niv 1 159 vers niv 2
		[7] = function (x) player:startEvent(0x00A9); end, -- Hume niv 2 169 vers niv 1
		[8] = function (x) player:startEvent(0x00A8); end, -- Hume niv 2 168 vers niv 3
		[9] = function (x) player:startEvent(0x00B2); end, -- Hume niv 3 178 vers niv 2

		[10] = function (x) player:startEvent(0x0097); end, -- Elvaan niv 0 151 vers niv 1
		[11] = function (x) player:startEvent(0x00A0); end, -- Elvaan niv 1 160 vers niv 0
		[12] = function (x) player:startEvent(0x00A1); end, -- Elvaan niv 1 161 vers niv 2
		[13] = function (x) player:startEvent(0x00AB); end, -- Elvaan niv 2 171 vers niv 1
		[14] = function (x) player:startEvent(0x00AA); end, -- Elvaan niv 2 170 vers niv 3
		[15] = function (x) player:startEvent(0x00B3); end, -- Elvaan niv 3 179 vers niv 2

		[16] = function (x) player:startEvent(0x0098); end, -- Galka niv 0 152 vers niv 1
		[17] = function (x) player:startEvent(0x00A2); end, -- Galka niv 1 162 vers niv 0
		[18] = function (x) player:startEvent(0x00A3); end, -- Galka niv 1 163 vers niv 2
		[19] = function (x) player:startEvent(0x00AD); end, -- Galka niv 2 173 vers niv 1
		[20] = function (x) player:startEvent(0x00AC); end, -- Galka niv 2 172 vers niv 3
		[21] = function (x) player:startEvent(0x00B4); end, -- Galka niv 3 180 vers niv 2

		[22] = function (x) player:startEvent(0x0099); end, -- Taru niv 0 153 vers niv 1
		[23] = function (x) player:startEvent(0x00A4); end, -- Taru niv 1 164 vers niv 0
		[24] = function (x) player:startEvent(0x00A5); end, -- Taru niv 1 165 vers niv 2
		[25] = function (x) player:startEvent(0x00AF); end, -- Taru niv 2 175 vers niv 1
		[26] = function (x) player:startEvent(0x00AE); end, -- Taru niv 2 174 vers niv 3
		[27] = function (x) player:startEvent(0x00B5); end, -- Taru niv 3 181 vers niv 2

		[28] = function (x) player:startEvent(0x009A); end, -- Mithra niv 0 154 vers niv 1
		[29] = function (x) player:startEvent(0x00A6); end, -- Mithra niv 1 166 vers niv 0
		[30] = function (x) player:startEvent(0x00A7); end, -- Mithra niv 1 167 vers niv 2
		[31] = function (x) player:startEvent(0x00B1); end, -- Mithra niv 2 177 vers niv 1
		[32] = function (x) player:startEvent(0x00B0); end, -- Mithra niv 2 176 vers niv 3
		[33] = function (x) player:startEvent(0x00B6); end, -- Mithra niv 3 182 vers niv 2
	}
	end
end;

-----------------------------------
-- onRegionLeave
-----------------------------------

function onRegionLeave(player,region)
end;

-----------------------------------
-- onEventUpdate
-----------------------------------

function onEventUpdate(player,csid,option)
	-- printf("CSID: %u",csid);
	-- printf("RESULT: %u",option);
	if ((csid >0x0095 and csid < 0x00B8)or csid ==0x0066 or csid ==0x0067 or csid ==0x0065) then
		player:setVar("Ru-Hmet-TP",1);
	end
end;

-----------------------------------
-- onEventFinish
-----------------------------------

function onEventFinish(player,csid,option)
	-- printf("CSID: %u",csid);
	-- printf("RESULT: %u",option);

	if (csid == 0x0065 and option == 1) then
		player:setPos(540,-1,-499.900,62,0x24);
		player:setVar("Ru-Hmet-TP",0);
	elseif ((csid >0x0095 and csid < 0x00B8)or  csid ==0x0066 or csid ==0x0067 or csid == 0x0065) then
		player:setVar("Ru-Hmet-TP",0);
	elseif (csid ==0x00C9) then
		player:setVar("PromathiaStatus",1);
	end

	if (csid == 0x7d00 and option==1) then
		player:setPos(420,0,398,68);
	end

end;